<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select  v-model="queryParams.type" >
          <el-option
            v-for="dict in typeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['member:memberInfo:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['member:memberInfo:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['member:memberInfo:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['member:memberInfo:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="memberInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="类型" align="center" :formatter="typeFormat" prop="type"/>
      <el-table-column label="姓名" align="center"  prop="name"/>
      <el-table-column label="学历" align="center" prop="education"/>
      <el-table-column label="毕业院校" align="center" prop="wentToSchool"/>
      <el-table-column label="职务" align="center" prop="post"/>
      <el-table-column label="工作单位" align="center" prop="workUnit"/>
      <el-table-column label="联系方式" align="center" prop="contactInformation"/>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['member:memberInfo:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['member:memberInfo:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改会员信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="auto">
        <el-row>
          <el-form-item label="会员类别" prop="type">
            <el-select style="width: 100%" v-model="form.type" placeholder="请选择类型">
              <el-option
                v-for="dict in typeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input class="input-class" v-model="form.name" placeholder="请输入姓名"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-radio-group v-model="form.sex">
                <el-radio v-for="dict in sexOptions" :key="dict.dictValue" :label="dict.dictValue">
                  {{ dict.dictLabel }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="出生年月" prop="brith">
              <el-date-picker style="width: 300px"  clearable size="large"
                              v-model="form.brith"
                              type="month"
                              value-format="yyyy-MM"
                              placeholder="选择出生年月"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="民族" prop="nation">
              <el-input class="input-class" v-model="form.nation" placeholder="请输入民族"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="籍贯" prop="nativePlace">
              <el-input class="input-class" v-model="form.nativePlace" placeholder="请输入籍贯"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学历" prop="education">
              <el-input class="input-class" v-model="form.education" placeholder="请输入学历"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="毕业院校" prop="wentToSchool">
              <el-input class="input-class" v-model="form.wentToSchool" placeholder="请输入毕业院校"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职务" prop="post">
              <el-input class="input-class" v-model="form.post" placeholder="请输入职务"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
           <el-col :span="12">
            <el-form-item label="政治面貌" prop="politicalLandscape">
              <el-input class="input-class" v-model="form.politicalLandscape" placeholder="请输入政治面貌"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="加入党派时间" prop="joinTime">
              <el-date-picker style="width: 300px" clearable size="small"
                              v-model="form.joinTime"
                              type="month"
                              value-format="yyyy-MM"
                              placeholder="选择加入党派时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
           <el-col :span="12">
            <el-form-item label="工作单位" prop="workUnit">
              <el-input class="input-class" v-model="form.workUnit" placeholder="请输入工作单位"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系方式" prop="contactInformation">
              <el-input class="input-class" v-model="form.contactInformation" placeholder="请输入联系方式"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
           <el-col :span="12">
            <el-form-item label="专业" prop="major">
              <el-input class="input-class" v-model="form.major" placeholder="请输入专业"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="参加工作时间" prop="workTime">
              <el-date-picker style="width: 300px" clearable size="small"
                              v-model="form.workTime"
                              type="month"
                              value-format="yyyy-MM"
                              placeholder="选择参加工作时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="技术职称" prop="technicalTitle">
              <el-input class="input-class" v-model="form.technicalTitle" placeholder="请输入技术职称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职级" prop="rank">
              <el-input class="input-class" v-model="form.rank" placeholder="请输入职级"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="任现职时间" prop="holdTime1">
              <el-date-picker style="width: 300px" clearable size="small"
                              v-model="form.holdTime1"
                              type="month"
                              value-format="yyyy-MM"
                              placeholder="选择任现职时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="任现职级时间" prop="holdTime2">
              <el-date-picker style="width: 300px" clearable size="small"
                              v-model="form.holdTime2"
                              type="month"
                              value-format="yyyy-MM"
                              placeholder="选择任现职级时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="任同职级时间" prop="holdTime3">
              <el-date-picker style="width: 300px" clearable size="small"
                              v-model="form.holdTime3"
                              type="month"
                              value-format="yyyy-MM"
                              placeholder="选择任同职级时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="国外学习单位" prop="abroadCompany">
              <el-input class="input-class" v-model="form.abroadCompany" placeholder="请输入国外学习单位"/>
            </el-form-item>
          </el-col>
        </el-row>
<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="状态" prop="state">-->
<!--              <el-input class="input-class" v-model="form.state" placeholder="请输入状态"/>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="类型" prop="state">-->
<!--              <el-input class="input-class" v-model="form.type" placeholder="请输入类型"/>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
        <el-row>
           <el-col :span="12">
            <el-form-item label="国外学习时间" prop="abroadTime" >
              <el-date-picker style="width: 300px" clearable size="small"
                              v-model="form.abroadTime"
                              type="month"
                              value-format="yyyy-MM"
                              placeholder="选择国外学习时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="备注" prop="remark">
              <el-input type="textarea" v-model="form.remark" placeholder="请输入备注"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listMemberInfo,
  getMemberInfo,
  delMemberInfo,
  addMemberInfo,
  updateMemberInfo,
  exportMemberInfo
} from '@/api/member/memberInfo'

export default {
  name: 'MemberInfo',
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员信息表格数据
      memberInfoList: [],
      //性别字典
      sexOptions: [],
      //类型字典
      typeOptions: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        sex: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        type: [
          {required: true, message: '类型不能为空', trigger: 'change'}
        ],
        name: [
          {required: true, message: '姓名不能为空', trigger: 'blur'}
        ],
        sex: [
          {required: true, message: '性别不能为空', trigger: 'change'}
        ],
        brith: [
          {required: true, message: '出生年月不能为空', trigger: 'change'}
        ],
        nation: [
          {required: true, message: '民族不能为空', trigger: 'blur'}
        ],
        nativePlace: [
          {required: true, message: '籍贯不能为空', trigger: 'blur'}
        ],
        education: [
          {required: true, message: '学历不能为空', trigger: 'blur'}
        ],
        wentToSchool: [
          {required: true, message: '毕业院校不能为空', trigger: 'blur'}
        ],
        post: [
          {required: true, message: '职务不能为空', trigger: 'blur'}
        ],
        politicalLandscape:[
          {required:true,message:'政治面貌不能为空',trigger:'blur'}
        ],
        joinTime: [
          {required: true, message: '加入党派时间不能为空', trigger: 'blur'}
        ],
        workUnit: [
          {required: true, message: '工作单位不能为空', trigger: 'blur'}
        ],
        contactInformation: [
          {required: true, message: '联系方式不能为空', trigger: 'blur'}
        ]
      }
    }
  },
  created() {
    this.getDicts('sys_user_sex').then(response => {
      this.sexOptions = response.data
    })
    this.getDicts('member_type').then(response => {
      this.typeOptions = response.data
    })
    this.getList()
  },
  methods: {
    /** 查询会员信息列表 */
    getList() {
      this.loading = true
      listMemberInfo(this.queryParams).then(response => {
        this.memberInfoList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        sex: null,
        brith: null,
        nation: null,
        nativePlace: null,
        education: null,
        wentToSchool: null,
        post: null,
        joinTime: null,
        workUnit: null,
        contactInformation: null,
        major: null,
        workTime: null,
        technicalTitle: null,
        rank: null,
        holdTime1: null,
        holdTime2: null,
        holdTime3: null,
        abroadCompany: null,
        abroadTime: null,
        state: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加会员信息'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getMemberInfo(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改会员信息'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMemberInfo(this.form).then(response => {
              this.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addMemberInfo(this.form).then(response => {
              this.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$confirm('是否确认删除会员信息编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return delMemberInfo(ids)
      }).then(() => {
        this.getList()
        this.msgSuccess('删除成功')
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$confirm('是否确认导出所有会员信息数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return exportMemberInfo(queryParams)
      }).then(response => {
        this.download(response.msg)
      })
    },
    typeFormat(row,column){
      return this.selectDictLabel(this.typeOptions, row.type);
    },
    sexFormat(row,cloumn){
      return this.selectDictLabel(this.sexOptions, row.sex);
    }
  }
}
</script>
<style scoped lang="scss">
.input-class{
  width: 300px;
}
</style>
